<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateOrderItemsTable extends Migration
{
    public function up()
    {
        Schema::create('order_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->index()->default(0);
	        $table->unsignedBigInteger('order_id')->index()->default(0)->comment('belongs to this order');
	        $table->unsignedBigInteger('vendor_id')->index()->default(0)->nullable()->comment('belongs to this vendor');
	        $table->unsignedBigInteger('product_id')->index()->default(0)->comment('belongs to this product');
	        $table->unsignedBigInteger('product_sku_id')->default(0)->index()->comment('belongs to this sku');
	        $table->string('product_title')->nullable();
	        $table->string('product_cover')->nullable();
	        $table->string('sku_name')->nullable();
	        $table->string('sku_pic')->nullable();
	        $table->string('sku_attr_value_index')->nullable();
	        $table->text('sku_attr_value')->nullable();
	        $table->unsignedInteger('amount')->index()->comment('how many user bought');
	        $table->decimal('cost', 10, 2)->default(0)->comment('the cost price');
	        $table->decimal('total_cost', 10, 2)->default(0);
	        $table->decimal('price', 10, 2)->default(0)->comment('final price');
	        $table->decimal('total_amount', 10, 2)->default(0);
	        $table->decimal('profit', 10, 2)->default(0)->comment('final price');
	        $table->decimal('total_profit', 10, 2)->default(0);
	        $table->string('delivery_status')->default('pending');
	         $table->boolean('has_commented')->default(false);
	        $table->text('delivery_data')->nullable()->comment('data about delivery');
            $table->timestamps();
	        $table->index(['created_at']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('order_items');
    }
}
